package com.crm.miaohe.security;

import lombok.Getter;
import org.springframework.security.core.GrantedAuthority;

import java.util.Arrays;

public enum Role implements GrantedAuthority {

    ACTIVATE(0L), CUSTOMER(1L), STAFF(2L), KEFU(3L), ADMIN(9L);

    @Getter
    final Long id;

    Role(Long id) {
        this.id = id;
    }

    @Override
    public String getAuthority() {
        return "ROLE_" + name();
    }

    public static Role fromId(Long id) {
        return Arrays.stream(Role.values()).filter(role -> id.equals(role.getId())).findFirst().orElse(null);
    }

}
